/*
 * @Autor: Qin Jiu
 * @Date: 2021-07-15 16:55:45
 * @LastEditors: Qinjiu
 * @LastEditTime: 2022-07-25 15:05:24
 * @Description: node服务文件，用于开发环境模拟服务器
 */
const express = require("express");
const history = require("connect-history-api-fallback");
const path = require("path");
const { createProxyMiddleware } = require("http-proxy-middleware");

const app = express();

// 解决vue项目history路由模式打包部署到node中，直接输入url访问时，页面会报404错误的问题
app.use("/", history());

// 映射指定目录中的静态资源
const staticRoot = path.resolve(__dirname, "../dist");
app.use(express.static(staticRoot));

// http代理
// app.use(
//   '/api',
//   createProxyMiddleware({
//     target: 'http://www.example.org',
//     changeOrigin: true
//   })
// );
// http://localhost:3000/api/foo/bar -> http://www.example.org/api/foo/bar

// http默认是80端口，https默认是443
const port = 8023;
app.listen(port, () => {
  console.log(`server listen on ${port}：${staticRoot}`);
});
